package com.star.uc.api;

import com.star.common.core.contract.R;
import com.star.uc.biz.AuthorizeRenderBizService;
import com.star.uc.contract.query.RenderAuthQuery;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * 授权跳转url地址
 *
 * @author zhouhengzhe
 * @version 1.0
 * @date 2023/12/19 17:47
 */
@RestController
@RequestMapping("/user/oauth")
@RequiredArgsConstructor
@Tag(name = "AuthorizeRenderController", description = "生成授权地址控制器")
public class AuthorizeRenderController {
    private final AuthorizeRenderBizService authorizeRenderBizService;

    @PostMapping("/render")
    @Operation(summary = "生成授权地址")
    public R<String> renderAuth(@RequestBody @Validated RenderAuthQuery renderAuthQuery, HttpServletResponse response) throws IOException {
        response.sendRedirect(authorizeRenderBizService.renderAuth(renderAuthQuery));
        return R.ok();
    }

}
